package com.itheima.controller.backend.check;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Pageinfo;
import com.itheima.service.backend.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/checkgroup")
@RestController
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;

    @GetMapping("deleteById")
    public Result deleteById(@RequestParam Integer id) {
        log.info("删除检查组，id={}", id);
        checkGroupService.deleteById(id);
        return new Result(true, "删除成功");
    }

    @GetMapping("findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(@RequestParam Integer setmealId) {
        log.info("根据套餐id查询检查组id，setmealId={}", setmealId);
        return new Result(true, "查询成功", checkGroupService.findCheckGroupIdsBySetmealId(setmealId));
    }

    @PostMapping("/findPage")
    public PageResult page(@RequestBody Pageinfo pageinfo
    ){
        Integer page = pageinfo.getCurrentPage();
        Integer pageSize = pageinfo.getPageSize();
        String name = pageinfo.getQueryString();
        log.info("分页查询, 参数: {},{},{},{},{},{}",page,pageSize,name);
        //调用service分页查询
        PageResult pageResult = checkGroupService.page(page,pageSize,name);
        return pageResult;
    }

    @GetMapping("/findAll")
    public Result findAll(){
        log.info("查询所有检查组");
        List<CheckGroup> checkItems = checkGroupService.list();
        return new Result(true,"查询成功",checkItems);
    }
    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id){
        log.info("根据id查询检查组, id:{}",id);
        CheckGroup checkGroup = checkGroupService.findById(id);
        return new Result(true,"查询成功",checkGroup);
    }




}
